<template>
  <div class="order-info-view">
    <div class="view-trade-info">
      {{orderStateValue}}
    </div>

    <div class="view-address">
      <table class="address-tab" v-if="orderInfo.userAddress!==null">
        <tr class="address-trh">
          <td class="address-choose"></td>
          <td class="address-info">收货地址</td>
          <td class="address-reve">收件人</td>
          <td class="address-mobile">手机</td>
          <td class="address-phone">电话</td></tr>
        <tr class="address-trd">
          <td class="address-choose"></td>
          <td class="address-info">{{orderInfo.userAddress}}</td>
          <td class="address-reve">{{orderInfo.receiver}}</td>
          <td class="address-mobile">{{orderInfo.mobile}}</td>
          <td class="address-phone">{{orderInfo.phone}}</td></tr>
      </table>
    </div>
    <div class="order-item">
      <div class="order-item-title">
        <div class="item-title-no">订单编号：{{orderInfo.goodsOrderId}}</div>
        <div class="item-title-date">订购时间：{{orderInfo.createDate}}</div>
        <!-- <div>卖家{{item.shopCompany.shopName}}</div> -->
      </div>
      <div class="order-item-detail" >
        <div class="item-detail">
          <div class="item-goods">宝贝信息</div>
          <div class="item-style">规格</div>
          <div class="item-price">单价</div>
          <div class="item-num">数量</div>
          <div class="item-cost">运费</div>
          <div class="item-amount">金额</div>
        </div>
        <div class="item-detail" v-for="(od,j) in orderInfo.shopGoodsOrderDetailList" :key="j">
          <div class="item-goods"><img :src="od.goodsUrl" width="50" height="50"><span>{{od.goodsName}}</span></div>
          <div class="item-style">{{od.goodsParam}}</div>
          <div class="item-price">{{od.goodsPrice.toFixed(2)}}</div>
          <div class="item-num">{{od.goodsNum}}</div>
          <div class="item-cost">{{od.expressCost.toFixed(2)}}</div>
          <div class="item-amount"> ¥ {{(od.goodsPrice*od.goodsNum).toFixed(2)}}</div>
        </div>
        <div class="order-remark">
          备注：{{orderInfo.orderRemark}}</textarea>
        </div>
        <div class="shop-order-flooter">
          <div class="order-total-amount">订单金额：¥ {{orderInfo.amount.toFixed(2)}} , 宝贝运费：¥ {{orderInfo.costPrice.toFixed(2)}} , 总合计金额：¥ {{(orderInfo.amount+orderInfo.costPrice).toFixed(2)}} </div>
        </div>
      </div>

    </div>
    <div class="view-shop" v-if="!isShowShop&&shopCompany!==null">
      <span class="view-shop-logo"><img :src="openImg(shopCompany.shopLogoUrl)"></span>
      <span class="view-shop-info">{{shopCompany.shopName}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        orderInfo: {},
        shopCompany: {},
        orderStateValue: '',
        isShowShop: false
      }
    },
    methods: {
      getOrderInfo (orderId, isShowShop) {
        this.isShowShop = isShowShop
        this.$http({
          url: this.$http.adornUrl('/pig-center-biz/network/shopGoodsOrder/orderInfo'),
          method: 'post',
          params: this.$http.adornParams({
            'orderId': orderId
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            // console.log(data)
            this.orderInfo = data.shopGoodsOrder
            this.shopCompany = data.shopGoodsOrder.shopCompany
            this.getOrderStateValue(this.orderInfo)
          }
        })
      },
      openImg (url) {
        if (url) {
          return this.$http.adornUrl(`/pig-file/center/file/openImg?url=${url}`)
        } else {
          return ''
        }
      },
      getOrderStateValue (orderInfo) {
        this.orderStateValue = '订单状态：'
        if (orderInfo.orderStatus === 0) {
          this.orderStateValue += '未支付'
        } else if (orderInfo.orderStatus === 10) {
          this.orderStateValue += '订单支付中'
        } else if (orderInfo.orderStatus === 20) {
          this.orderStateValue += '订单结算成功,店小二在为您配货'
        } else if (orderInfo.orderStatus === 30) {
          this.orderStateValue += '订单发货中'
        } else if (orderInfo.orderStatus === 150) {
          this.orderStateValue += '订单退货'
        } else if (orderInfo.orderStatus === 100) {
          this.orderStateValue += '订单交易完成'
        } else if (orderInfo.orderStatus === 300) {
          this.orderStateValue += '订单交易关闭'
        } else if (orderInfo.orderStatus === 12) {
          this.orderStateValue += '证书验证异常'
        } else if (orderInfo.orderStatus === -1) {
          this.orderStateValue += '用户取消订单'
        } else if (orderInfo.orderStatus === -99) {
          this.orderStateValue += '订单结算失败'
        }
        if (orderInfo.orderStatus > 20) {
          this.$http({
            url: this.$http.adornUrl('/pig-center-biz/mall/shopGoodsLogistics/findLogisticsList'),
            method: 'post',
            params: this.$http.adornParams({
              'orderId': orderInfo.goodsOrderId
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              console.log(data)
              let logisticsList = data.logisticsList
              for (let i = 0; i < logisticsList.length; i++) {
                this.orderStateValue += ' ' + logisticsList[i].expressName + ' 单号：' + logisticsList[i].expressCode
              }
            }
          })
          console.log(this.orderStateValue)
        }
      }
    }
  }
</script>

<style scoped>
  .order-info-view{
    width: 100%;
  }
  .view-trade-info{
    font-size: 16px;
    color: red;
    font-family: "microsoft yahei";
    font-weight: bold;
    height: 50px;
    line-height: 50px;
    border: 1px solid #D2D2D2;
    background: #e4e7ed;
    margin: 20px 0;
    padding-left: 20px;
  }
  .view-shop{
    display: flex;
    justify-content: flex-start;
    align-items: center;
    height: 80px;
    border: 1px solid #D2D2D2;
    background: #e4e7ed;
  }
  .view-shop-logo{width: 70px;height: 70px;margin: 0 20px;}
  .view-shop-logo img{max-width: 70px;width: auto;max-height: 70px;height: auto;}
  .view-shop-info{width: 200px;overflow:hidden;white-space: nowrap;text-overflow: ellipsis;}
  .view-address{
    width: 100%;
  }
  .address-tab{
    width: 100%;
    border: 1px solid #D2D2D2;
    margin: 24px 0px 10px;
    border-spacing: 0px;
    font-size: 12px;
  }

  .address-trh{background: #e4e7ed;height: 40px;}
  .address-trd{height: 32px;}
  .address-choose{width: 2%;text-align: center;}
  .address-info{width: 50%;}
  .address-reve{width: 15%;}
  .address-oper{width: 15%;text-align: center;}
  .address-mobile{width: 15%;}

  .order-item{
    width: 100%;
    font-size: 12px;
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 16px;
    border:1px solid #D2D2D2;
  }
  .order-item-title{
    width: 100%;
    background: #e4e7ed;
    display: flex;
    /* justify-content: space-between; */
    flex-wrap: wrap;
    align-items: center;
    height: 40px;
    border-bottom:1px solid #D2D2D2;
  }
  .item-title-no,.item-title-date{width:360px;padding-left: 20px;}
  .order-item-detail{
    width: 100%;
  }
  .order-remark{
    width: 100%;
    border-top:1px solid #D2D2D2;
    vertical-align: top;
    padding: 20px;
    display: flex;
    align-items: flex-start;
  }
  .item-detail{
    width: 100%;
    display: flex;
    flex-wrap: nowrap;
    padding: 8px 0;
  }
  .item-goods{
    width: 45%;
    padding-left: 20px;
    display: flex;
    align-items: flex-start;
  }
  .item-goods span{
    padding-left: 10px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .item-price,.item-num,.item-amount,.item-cost{
    width: 10%;
  }
  .item-style{
   width: 15%;
  }
  .shop-order-flooter{
    width: 100%;
    height: 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top:1px solid #D2D2D2;
    background: #e4e7ed;
  }
  .order-total-amount{
    width: 500px;
    font-size: 14px;
    font-weight: bold;
    color: red;
    padding-left: 20px;
  }
</style>
